/**
 * Created by Administrator on 2015/11/26 0026.
 */

var sha1 = require('../utils/sha1.js');

function getNoncestr() {
    return Math.random().toString(36).substr(2); // 生成随机字符串
}

function getTimeStamp() {
    return parseInt(Date.now().toString().substring(0, 10));
}

function getUrl(req) {
    return "http://ws.taoseoer.com" + req.originalUrl;
}

exports.register = function (app) {
    var token = 'taoseoer';
    app.get('/checkSignature', function (req, res, next) {
        var echostr = req.query.echostr;
        var signature = req.query.signature;
        var timestamp = req.query.timestamp;
        var nonce = req.query.nonce;

        var tmpArr = [token, timestamp, nonce]
        tmpStr = tmpArr.sort().join("")

        shaStr = sha1(tmpStr)
        console.log('signature:' + signature);
        if (shaStr == signature) {
            console.log("success echostr:" + echostr)
            res.send(echostr);
        } else {
            console.log("error:" + echostr)
            res.send("errortest");
        }
    });
}